package spring.cloud.sleuth.client.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
public class SampleController {
    private static final Log LOG = LogFactory.getLog(SampleController.class);
    @Autowired
    private RestTemplate restTemplate;

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    private static final String BASE_URL = "http://localhost:9942";

    @RequestMapping(value = "/sleuth", method = {RequestMethod.GET})
    public String sleuth() throws Exception {
        String servicePath = "service";
        LOG.info(servicePath);
        Thread.sleep(200L);
        return restTemplate.getForObject(BASE_URL + "/" + servicePath, String.class);
    }
}
